// SurfaceContainer.h: interface for the SurfaceContainer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SURFACECONTAINER_H__DD9BFF84_716C_42CF_A31A_341B6B2448C2__INCLUDED_)
#define AFX_SURFACECONTAINER_H__DD9BFF84_716C_42CF_A31A_341B6B2448C2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iostream>
#include "..\SDL\include\SDL.h"
#include "..\Figure\Point.h"
#include "..\SDL\include\SDL_image.h"
#include "..\Image\Image.h"
#include "..\Exceptions\drawingExcep.h"
#include "..\Exceptions\msjExcep.h"

#define SWAP(x,y,temp) temp=x;x=y;y=temp
#define sge_clip_xmin(pnt) pnt->clip_rect.x
#define sge_clip_xmax(pnt) pnt->clip_rect.x + pnt->clip_rect.w-1
#define sge_clip_ymin(pnt) pnt->clip_rect.y
#define sge_clip_ymax(pnt) pnt->clip_rect.y + pnt->clip_rect.h-1
#define EPSILON 0.01


class Image;

class SurfaceContainer  {
	
	public:

		void initializeSurface(int width, int height, Color* screenColor);
	
		static SurfaceContainer* getInstance();

		virtual ~SurfaceContainer();

		void drawPoint(const Point &p1, SDL_Color *color);

		void drawLine(const Point &p1, const Point &p2, SDL_Color *color);

		void drawRectangle(const Point &p1, const Point &p2, const Point &p3, const Point &p4, SDL_Color *color);

		void drawCircle(const Point &p1, int ratio, SDL_Color *color);

		void lockSurface();

		void flip();

		void unlockSurface();
		
		void fillRectangle(Point &vertice,int base,int altura, SDL_Color *color);
	
		void fillCircle(Point &center,int radio, SDL_Color* color) throw (DrawingExcep);

		void drawTexturedLine(Image *bitmap, Sint16 x1, Sint16 x2, Sint16 y, Sint16 sx1, Sint16 sy1, Sint16 sx2, Sint16 sy2, int posicion);

		void fillTexture(Image* bitmap, Point A, Point B, Point C, Point A_BMP, Point B_BMP, Point C_BMP, int posicion);
	
		bool pointInScreen(Point p);

		bool acceptRadius(Point cen, int rad);
		
		bool acceptLimits(Point p, int base, int alt);
		
		int getSurfaceHeight();

		int getSurfaceWidth();

		static void destroy();

	private:
		
		Uint32 getPixelInt(SDL_Surface *image, Point* pto);
		
		void drawPixel(int x, int y, Uint32 color) throw (DrawingExcep);

		void drawPixel(int x, int y,SDL_Color *color);

		static SDL_Surface *surface;

		SurfaceContainer();

		static SurfaceContainer* instance;

		double inclination(const Point &p1, const Point &p2);

		void bresenham(int x1, int y1, int x2, int y2, SDL_Color* color);

		void rasterCircle(int x0, int y0, int radius, SDL_Color* color);

		void rasterCircle(int x0, int y0, int radius, SDL_Color* color, SDL_Color* colorRelleno);

		void swap(int* a, int* b);

		int widht;

		int heigth;

		Color* screenColor;

};

#endif // !defined(AFX_SURFACECONTAINER_H__DD9BFF84_716C_42CF_A31A_341B6B2448C2__INCLUDED_)
